<?php
  $link = mysql_connect('', 'admin_xbq', 'nihao')
      or die('Could not connect: ' . mysql_error());
  echo 'Connected successfully';
  
  if (isset($_GET['db'])) {
    $sql = "Drop database ". $_GET['db'].";";
    mysql_query($sql);
  }

  if (isset($_POST['new_db_name'])) {
    $sql = "CREATE DATABASE ". $_POST['new_db_name'].";";
    mysql_query($sql);
  }

  $query = "show databases;";
  $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  
  echo "<div  align=\"center\">";
  echo "<table class=\"style2\"  width=\"250\">\n";
  echo "<tr>\n
        <th>Name of databases</th>
        <th>Delete</th>
        </tr>\n";
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
//      while ($line!="mysql" && $line!="phpmyadmin" && $line!="nihao" && $line!="information_schema") {
      echo "\t<tr>\n";
      foreach ($line as $col_value) {
            echo "\t\t<td><a href=\"showtabs.php?db=".$col_value."\">".$col_value."</a></td>\n";
            echo "\t\t<td align=\"center\" width=\"50\">\n";
            echo "\t\t\t<a href=\""; 
            echo $_SERVER['PHP_SELF'];
            echo "?db=".$col_value."\"><img src=\"img/b_drop.png\" Onclick=\"if(!confirm('Are you sure to delete database?')) return false;\" alt=\"Drop database\" /></a>\n";
            echo "\t\t</td>\n";
      }
      echo "\t</tr>\n";
//      }
  }
  echo "</table>\n";
  echo "</div>";
  
  mysql_free_result($result);
  
  mysql_close($link);
?>

<div align="right">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<table>
<tr class="style3">
  <td class="style3">Enter database name:</td>
  <td></td>
</tr>
<tr class="style3">
  <td class="style3"><input name="new_db_name" type="text" /></td>
  <td class="style3"><input name="create_new_db" type="submit" value="Create" /></td>
</tr>
</table>
</form>
</div>
